package pers.rcklos.myserver.controller;

import java.util.ArrayList;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import pers.rcklos.myserver.biz.CommentBiz;
import pers.rcklos.myserver.entity.CommentItem;
import pers.rcklos.myserver.entity.PaperItem;
import pers.rcklos.myserver.entity.SpUser;

@Controller
public class CommentController {
	
	private CommentBiz commentBiz;
	
	@GetMapping("/comment/query_all")
	public String queryAllPapers(@RequestParam(defaultValue = "0")int start, Model model) {
//		ArrayList<PaperItem> list = paperBiz.queryAllPapers();
		model.addAttribute("page", start);
		ArrayList<CommentItem> list = commentBiz.queryPageOfComments(start, 10);
		model.addAttribute("comments", list);
		model.addAttribute("query_size", list.size());
		// 装配head部分
		model.addAttribute("thead", 2);			// 纸条表
		return "admin";
	}
	
	@GetMapping("/comment/delete")
	public String deleteComment(String comm_id, HttpSession session) {
		if(comm_id==null||comm_id.equals("")) {
			return "param is invalid";
		}
	
		boolean isSuccess = commentBiz.deleteCommentById(Integer.parseInt(comm_id));
		return isSuccess?"success":"fail!";
	}
	
	
	@Autowired
	public void setCommentBiz(CommentBiz commentBiz) {
		this.commentBiz = commentBiz;
	}
	
}
